import Mock from 'mockjs';
import type { MockRequestOptions } from '../types/mock';

interface OrderItem {
  id: number;
  orderNo: string;
  productImage: string;
  productInfo: string;
  specifications: string;
  quantity: number;
  amount: number;
  shippingFee: number;
  orderStatus: string;
  shippingStatus: string;
  trackingNo: string;
  paymentTime: string;
  shippingInfo: string;
  supplier: string;
}

export const mockOrderList = Mock.mock({
  'list|100': [
    {
      'id|+1': 100000,
      'orderNo': '@guid',
      'productImage': '@image("200x200", "#50B347", "#FFF", "Mock")',
      'productInfo': '@ctitle(5, 10)',
      'specifications': '@ctitle(2, 4)',
      'quantity|1-10': 1,
      'amount|1-9999.2': 1,
      'shippingFee|10-50.2': 10,
      'orderStatus|1': ['待付款', '待发货', '待收货', '已完成', '已取消'],
      'shippingStatus|1': ['未发货', '已发货', '已签收'],
      'trackingNo': '@string("upper", 12)',
      'paymentTime': '@datetime',
      'shippingInfo': '@cparagraph(1, 2)',
      'supplier': '@cname'
    } as unknown as OrderItem,
  ],
});

export default [
  {
    url: '/api/orders',
    method: 'get',
    response: () => ({
      code: 200,
      message: 'success',
      data: mockOrderList.list,
    }),
  },
  {
    url: '/api/orders/:id',
    method: 'get',
    response: (options: MockRequestOptions) => {
      const id = parseInt(options.url.split('/').pop() || '100000', 10);
      return {
        code: 200,
        message: 'success',
        data: mockOrderList.list.find((item: OrderItem) => item.id === id),
      };
    },
  },
];